package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Scanner;

public class RegDemo {
    public static void main(String[] args)throws Exception {
//        System.out.println("欢迎登录！请输入用户名，密码，昵称，年龄:>");
//        Scanner scanner = new Scanner(System.in);
//        String name = scanner.next();
//        String pwd = scanner.next();
//        String nickname = scanner.next();
//        int age = scanner.nextInt();
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo(),"欢迎注册");
        String sql = "insert into userinfo(username,password,nickname,age) values('";
        sql += userInfo.getUsername() + "','" + userInfo.getPassword() + "','" + userInfo.getNickname() + "'," + userInfo.getAge() + ")";
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true"
                ,"root","root");
        Statement statement = connection.createStatement();
        int rows = statement.executeUpdate(sql);
        if (rows > 0){
            System.out.println("注册成功！");
        }else{
            System.out.println("注册失败！");
        }
        connection.close();
        }
    }